const app = getApp()

Page({
  data: {
    iconMap: {
      xlxs: '/assets/svg/excel.svg',
      xls: '/assets/svg/excel.svg',
      docx: '/assets/svg/word.svg',
      doc: '/assets/svg/word.svg',
      ppt: '/assets/svg/powerpoint.svg',
      pdf: '/assets/svg/pdf.svg',
      jpg: '/assets/svg/image.svg',
      png: '/assets/svg/image.svg',
    },
    list: [],
    isEmpty: false
  },
  openFileDing(event) {
    const file = this.data.list[event.currentTarget.dataset.index]
    console.log('file', file)
  

    dd.previewFileInDingTalk({
      spaceId: file.space_id,
      fileName: file.name,
      corpId: 'dingf3b170a7280901ae35c2f4657eb6378f',
      fileSize: file.size,
      fileType: file.type,
      fileId: file.file_id_ding,
      success: () => {},
      fail: () => {},
      complete: () => {},
    });
  },
  openImg (event) {
    const url = this.data.list[event.currentTarget.dataset.index]
    console.log('file', url)

    dd.navigateTo({
      url: '/pages/img/img?url='+url.img_url,
      success: () => {},
      fail: () => {},
      complete: () => {},
    });
  },
  onLoad(query) {
    console.log('query', query)

    app.https('GET','/api/DingIndex/attachments',{ folderId: query.id }).then(r => {
      console.log('r',r)
      if (r.data.length === 0) {
        this.setData({
          isEmpty: true
        })
      } else {
        this.setData({
          list: r.data,
          isEmpty: false
        })
      }
      
    })
  },
});
